﻿@page "/thirdPartyIdp"
@inherits AdminCompontentBase

<PageTitle>
    @T("ThirdPartyIdp")
</PageTitle>

<DefaultCard>
    <AutoHeight>
        <HeaderContent>
            <div class="d-flex mb-6">
                <SSearch @bind-Value="Search" />
                <MSpacer />
                <SButton Small OnClick="() => OpenAddThirdPartyIdpDialog()" BorderRadiusClass="rounded-lg">
                    <SIcon Size=18 IsDefaultToolTip="false">@IconConstants.Add</SIcon>
                    <span class="ml-2 btn">@T("Add")</span>
                </SButton>
            </div>
        </HeaderContent>
        <AutoHeightContent>
            <SDataTable
                Dense
                Headers="_headers" 
                Items="ThirdPartyIdps" 
                TItem="ThirdPartyIdpDto" 
                ItemsPerPage="PageSize">
                <HeaderColContent Context="header">
                    <span>@header.Text</span>
                </HeaderColContent>
                <ItemColContent>
                    @switch (context.Header.Value)
                    {
                        case nameof(ThirdPartyIdpDto.Icon):
                            <div class="hover-pointer" @onclick="()=> OpenUpdateThirdPartyIdpDialog(context.Item)">
                                 <MAvatar Size="20">
                                    <img src="@context.Item.Icon" />
                                </MAvatar>
                            </div>                         
                            break;
                        case nameof(ThirdPartyIdpDto.Name):
                            <div>
                                <span>@context.Item.Name</span>
                            </div>
                            break;
                        case (nameof(ThirdPartyIdpDto.DisplayName)):
                            <span>@context.Item.DisplayName</span>
                            break;
                        case nameof(ThirdPartyIdpDto.AuthenticationType):
                            <span>@T(context.Item.AuthenticationType.ToString())</span>
                            break;
                        case nameof(ThirdPartyIdpDto.ThirdPartyIdpType):
                            <span>@T(context.Item.ThirdPartyIdpType.ToString())</span>
                            break;
                        case nameof(UserDto.Enabled):
                            <EnableChip Value=context.Item.Enabled />
                            break;
                        case nameof(ThirdPartyIdpDto.CreationTime):
                            <SDateTimeTitle Value=context.Item.CreationTime />
                            break;
                        case "Action":
                            <div class="d-flex">
                                <MButton Class="mr-4" Icon OnClick="()=> OpenUpdateThirdPartyIdpDialog(context.Item)">
                                    <SIcon Tooltip="@T("Edit")">@IconConstants.Update</SIcon>
                                </MButton>
                                <MButton Class="mr-4" Icon OnClick="()=> OpenRemoveThirdPartyIdpDialog(context.Item)">
                                    <SIcon Tooltip="@T("Delete")">@IconConstants.Remove</SIcon>
                                </MButton>
                            </div>
                            break;
                        default:
                            <SItemCol Value="@context.Value"></SItemCol>
                            break;
                    }
                </ItemColContent>
            </SDataTable>
        </AutoHeightContent>
        <FooterContent>
            <SPagination Class="mt-5" @bind-Page="Page" @bind-PageSize=PageSize Total=Total />
        </FooterContent>
    </AutoHeight>
</DefaultCard>

<AddThirdPartyIdpDialog @bind-Visible="AddThirdPartyIdpDialogVisible" OnSubmitSuccess=GetThirdPartyIdpsAsync />
<UpdateThirdPartyIdpDialog ThirdPartyIdpId=CurrentThirdPartyIdpId @bind-Visible="UpdateThirdPartyIdpDialogVisible" OnSubmitSuccess=GetThirdPartyIdpsAsync />